Overview
Multi-node training allows you to scale CLIP training across multiple machines, enabling training on massive datasets with large models. OpenCLIP supports multi-node training through both native PyTorch distributed (torchrun) and SLURM cluster management.OpenCLIP has been battle-tested on clusters with up to 1024 A100 GPUs, demonstrating robust scalability for large-scale training.
Prerequisites
- Multiple machines with GPUs connected via high-bandwidth network
- Network configuration allowing inter-node communication
- Shared filesystem accessible from all nodes (recommended)
- SLURM cluster (for SLURM-based training) or manual node coordination
Multi-Node with torchrun
Basic Setup
Thetorchrun launcher supports multi-node training with minimal configuration. The key is specifying the master node’s address and the number of nodes.
--nproc_per_node=4: Number of GPUs per node (4 in this example)--nnodes=2: Total number of nodes--node_rank=$NODE_RANK: Rank of current node (0 for master, 1, 2, … for workers)--rdzv_endpoint=$MASTER_ADDR:$MASTER_PORT: Address of the master node
Environment Variables
Set these environment variables on each node: Master Node (Node 0):Complete Multi-Node Example
Here’s a complete example with 2 nodes, 4 GPUs each: On Master Node (192.168.1.10):SLURM-Based Training
SLURM is the recommended approach for large-scale cluster training. It automatically handles node allocation, environment setup, and process launching.Basic SLURM Script
--nodes=32: Number of nodes to allocate--gres=gpu:4: Request 4 GPUs per node--ntasks-per-node=4: Launch 4 tasks (1 per GPU) per node--cpus-per-task=6: Allocate 6 CPU cores per task (for data loading)--wait-all-nodes=1: Wait for all nodes to be ready before starting
Production SLURM Example
Here’s a production-ready SLURM script for training ViT-L/14 on LAION-400M:Submitting SLURM Jobs
Network Configuration
Firewall Settings
Ensure communication ports are open between nodes:Network Backend
Configure the distributed backend for your hardware: NVIDIA GPUs with NCCL (recommended):InfiniBand Optimization
For clusters with InfiniBand, optimize NCCL settings:Distributed Training Optimizations
Memory-Efficient Distributed Loss
For multi-node training, use these flags to reduce memory usage from O(n²) to O(n):- Memory usage: O(batch_size × num_gpus)²
- Example: 256 batch size × 128 GPUs = 8GB+ logit matrix
- Memory usage: O(batch_size × num_gpus)
- Same numerical results
- Essential for large-scale training (64+ GPUs)
Gradient Accumulation
Simulate larger batch sizes across nodes:Remote Checkpoint Syncing
For multi-node training, sync checkpoints to remote storage (S3, shared filesystem):--logs: Local checkpoint directory--remote-sync: Remote path (s3:// or shared filesystem path)--remote-sync-frequency 300: Sync every 300 seconds (5 minutes)--delete-previous-checkpoint: Save disk space on local nodes
Resume from Remote Checkpoint
SLURM Job Management
Interactive SLURM Session
For debugging, request interactive session:Monitor Job Progress
Job Arrays for Hyperparameter Search
Troubleshooting Multi-Node Training
Nodes Can’t Communicate
Symptom: Training hangs at initialization Solutions:- Check firewall settings
- Verify
MASTER_ADDRis reachable from all nodes: - Check SLURM node allocation:
NCCL Initialization Errors
Symptom:- Enable NCCL debugging:
- Check GPU visibility:
- Verify InfiniBand configuration (if applicable)
Inconsistent Results Across Nodes
Symptom: Different nodes show different loss values Solutions:- Ensure same code version on all nodes
- Check data is accessible from all nodes
- Verify
--seedis set for reproducibility - Use
--wait-all-nodes=1in SLURM
Out of Memory on Some Nodes
Symptom: OOM error on specific nodes Solutions:- Check GPU memory is equal across nodes:
- Use
--grad-checkpointingfor memory efficiency - Reduce
--batch-sizeper GPU - Enable
--local-loss --gather-with-grad
Performance Optimization
Network Bandwidth
Monitor network usage during training:Scaling Efficiency
Measure scaling efficiency:- Use
--local-loss --gather-with-grad - Ensure sufficient batch size per GPU (128-512)
- Use WebDataset format
- Optimize
--workersfor data loading
Benchmark Multi-Node Performance
Example: Large-Scale Training Configuration
Training ViT-H/14 on LAION-2B with 256 GPUs (64 nodes × 4 GPUs):Next Steps
Distributed Training
Learn about advanced distributed training techniques
Configuration
Explore all training configuration options
Single-Node Training
Start with single-node training before scaling
Data Preparation
Prepare large-scale datasets for multi-node training
